import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:city_pickers/city_pickers.dart';
import 'package:du_application/model/UploadModel.dart';

import 'package:du_application/pages/HomePage.dart';
import 'package:du_application/pages/person_center/AddressEditPage.dart';
import 'package:du_application/provide/AuthProvider.dart';
import 'package:du_application/provide/InfoProvider.dart';
import 'package:du_application/units/image.dart';
import 'package:easy_alert/easy_alert.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provide/provide.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../data.dart';

class UserInfoPage extends StatefulWidget {
  UserInfoPage({Key key}) : super(key: key);

  @override
  _UserInfoPageState createState() => _UserInfoPageState();
}

class _UserInfoPageState extends State<UserInfoPage> {
  @override
  Widget build(BuildContext context) {
    String _nickname;

    // CityPickerUtil cityPickerUtils = CityPickers.utils();
    final _loadingContainer = Container(
        width: ScreenUtil().setHeight(1080),
        height: ScreenUtil().setHeight(1920),
        constraints: BoxConstraints.expand(),
        color: Colors.black,
        child: Center(
          child: Opacity(
            opacity: 0.9,
            child: SpinKitWave(
              color: Colors.white,
              size: 50.0,
            ),
          ),
        ));
    show() {
      CityPickers.showFullPageCityPicker(
        theme: ThemeData(
          accentColor: Colors.black,
        ),
        context: context,
        provincesData: provincesData,
        citiesData: citiesData,
      ).then((Result result) {
        Provide.value<InfoProvider>(context)
            .setCode(result.provinceId, result.cityId, result.areaId);
      });
    }

    return Provide<InfoProvider>(builder: (context, child, index) {
      _openGallery() async {
        var image = await ImagePicker.pickImage(source: ImageSource.gallery);
        return image;
      }

      return index == null || index.infoModel == null
          ? _loadingContainer
          : Scaffold(
              appBar: AppBar(
                title: Text("资料修改"),
                centerTitle: true,
              ),
              body: Container(
                  padding: EdgeInsets.symmetric(
                      horizontal: ScreenUtil().setSp(20),
                      vertical: ScreenUtil().setSp(40)),
                  child: Column(
                    children: <Widget>[
                      Container(
                          padding: EdgeInsets.symmetric(
                            horizontal: ScreenUtil().setSp(40),
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                topRight:
                                    Radius.circular(ScreenUtil().setSp(20)),
                                topLeft:
                                    Radius.circular(ScreenUtil().setSp(20))),
                            color: Colors.white,
                          ),
                          height: ScreenUtil().setHeight(150),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: <Widget>[
                              Text("头像"),
                              InkWell(
                                  onTap: () async {
                                    var image = await _openGallery();
                                    UploadModel uploadModel =
                                        await upload(context, image);
                                    if (uploadModel.errno == 0) {
                                      index.updateInfo(
                                          nickname: index
                                              .infoModel.data.user.nickname,
                                          gender:
                                              index.infoModel.data.user.gender,
                                          avatar: uploadModel.data.url);
                                    }
                                  },
                                  child: Row(
                                    children: <Widget>[
                                      Container(
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(999999999)),
                                          ),
                                          height: ScreenUtil.getInstance()
                                              .setHeight(150),
                                          width: ScreenUtil.getInstance()
                                              .setHeight(150),
                                          child: ClipOval(
                                            child: CachedNetworkImage(
                                              imageUrl: index
                                                  .infoModel.data.user.avatar,
                                              fit: BoxFit.cover,
                                              placeholder: (context, url) =>
                                                  Image.asset(
                                                      'assets/loading.jpg'),
                                            ),
                                          )),
                                      Icon(
                                        Icons.arrow_forward_ios,
                                        color: Colors.grey[600],
                                        size:
                                            ScreenUtil.getInstance().setSp(40),
                                      )
                                    ],
                                  ))
                            ],
                          )),
                      InkWell(
                          onTap: () {
                            showModalBottomSheet(
                                shape: RoundedRectangleBorder(
                                    borderRadius:
                                        BorderRadiusDirectional.circular(10)),
                                context: context,
                                builder: (_) {
                                  return GestureDetector(
                                    child: Stack(children: [
                                      Positioned(
                                          right: ScreenUtil().setWidth(10),
                                          top: ScreenUtil().setWidth(10),
                                          child: IconButton(
                                            icon: Icon(Icons.close),
                                            onPressed: () {
                                              Navigator.of(context).pop();
                                            },
                                          )),
                                      Container(
                                        padding: EdgeInsets.symmetric(
                                            horizontal:
                                                ScreenUtil().setWidth(30),
                                            vertical:
                                                ScreenUtil().setHeight(120)),
                                        height: ScreenUtil().setHeight(1200),
                                        child: TextField(
                                          textInputAction: TextInputAction.done,
                                          onChanged: (value) {
                                            _nickname = value;
                                          },
                                          //  keyboardType:TextInputType.,
                                          // obscureText: true,
                                          style: TextStyle(color: Colors.black),
                                          decoration: InputDecoration(
                                            border: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(15.0),
                                              //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                            ),
                                            enabledBorder: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(15.0),
                                              //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                            ),
                                            labelText: '昵称',
                                            labelStyle:
                                                TextStyle(color: Colors.black),
                                            hintText: '请输入修改昵称',
                                            focusColor: Colors.black,
                                            focusedBorder: InputBorder.none,
                                          ),
                                        ),
                                      ),
                                      Positioned(
                                          right: ScreenUtil().setWidth(40),
                                          bottom: ScreenUtil().setHeight(40),
                                          child: InkWell(
                                              onTap: () {
                                                if (_nickname == null ||
                                                    _nickname.length <= 0) {
                                                  Alert.toast(context, "长度太小了",
                                                      position:
                                                          ToastPosition.bottom,
                                                      duration:
                                                          ToastDuration.long);
                                                } else {
                                                  index.updateInfo(
                                                      nickname: _nickname,
                                                      gender: index.infoModel
                                                          .data.user.gender,
                                                      avatar: index.infoModel
                                                          .data.user.avatar);
                                                  Navigator.pop(context);
                                                }
                                              },
                                              child: Container(
                                                  padding: EdgeInsets.symmetric(
                                                      horizontal: ScreenUtil()
                                                          .setSp(40),
                                                      vertical: ScreenUtil()
                                                          .setSp(20)),
                                                  color: Colors.cyan[400],
                                                  margin: EdgeInsets.only(
                                                      left: ScreenUtil()
                                                          .setSp(60)),
                                                  child: Text(
                                                    "确认",
                                                    style: TextStyle(
                                                        color: Colors.white),
                                                  ))))
                                    ]),
                                    onTap: () {
                                      return false;
                                    },
                                  );
                                });
                          },
                          child: Container(
                              padding: EdgeInsets.symmetric(
                                horizontal: ScreenUtil().setSp(40),
                              ),
                              color: Colors.white,
                              height: ScreenUtil().setHeight(150),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Text("昵称"),
                                  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: <Widget>[
                                      Text(index.infoModel.data.user.nickname),
                                      Icon(
                                        Icons.arrow_forward_ios,
                                        color: Colors.grey[600],
                                        size:
                                            ScreenUtil.getInstance().setSp(40),
                                      )
                                    ],
                                  )
                                ],
                              ))),
                      InkWell(
                          onTap: () {},
                          child: Container(
                              padding: EdgeInsets.symmetric(
                                horizontal: ScreenUtil().setSp(40),
                              ),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.only(
                                    bottomLeft:
                                        Radius.circular(ScreenUtil().setSp(20)),
                                    bottomRight: Radius.circular(
                                        ScreenUtil().setSp(20))),
                                color: Colors.white,
                              ),
                              height: ScreenUtil().setHeight(150),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Text("性别"),
                                  DropdownButtonHideUnderline(
                                      child: DropdownButton(
                                    items: [
                                      DropdownMenuItem(
                                        child: new Text('男'),
                                        value: 0,
                                      ),
                                      DropdownMenuItem(
                                        child: new Text('女'),
                                        value: 1,
                                      ),
                                    ],
                                    hint: new Text('请选择'),
                                    onChanged: (value) {
                                      index.updateInfo(
                                          nickname: index
                                              .infoModel.data.user.nickname,
                                          gender: value,
                                          avatar:
                                              index.infoModel.data.user.avatar);
                                    },
//              isExpanded: true,
                                    value: index.infoModel.data.user.gender,
                                    elevation: 24, //设置阴影的高度
                                    style: new TextStyle(
                                      //设置文本框里面文字的样式
                                      color: Color(0xff4a4a4a),
                                    ),
//              isDense: false,//减少按钮的高度。默认情况下，此按钮的高度与其菜单项的高度相同。如果isDense为true，则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时，非常有用
                                    // iconSize: 40.0,
                                    icon: Icon(
                                      Icons.arrow_forward_ios,
                                      color: Colors.grey[600],
                                      size: ScreenUtil.getInstance().setSp(40),
                                    ),
                                  ))
                                ],
                              ))),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().setSp(20)),
                        padding: EdgeInsets.symmetric(
                          horizontal: ScreenUtil().setSp(40),
                        ),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.only(
                              topRight: Radius.circular(ScreenUtil().setSp(20)),
                              topLeft: Radius.circular(ScreenUtil().setSp(20))),
                        ),
                        alignment: Alignment.centerLeft,
                        height: ScreenUtil().setHeight(120),
                        child: Text(
                          "地址管理",
                          style: TextStyle(fontSize: ScreenUtil().setSp(30)),
                        ),
                      ),
                      Stack(children: [
                        Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                bottomLeft:
                                    Radius.circular(ScreenUtil().setSp(20)),
                                bottomRight:
                                    Radius.circular(ScreenUtil().setSp(20))),
                            color: Colors.white,
                          ),
                          width: ScreenUtil().setWidth(1080),
                          height: ScreenUtil().setHeight(800),
                          child: index.infoModel.data.address.length > 0
                              ? CarouselSlider(
                                  height: ScreenUtil().setHeight(500),
                                  items: index.infoModel.data.address
                                      .asMap()
                                      .keys
                                      .toList()
                                      .map((item) {
                                    return Builder(
                                      builder: (BuildContext context) {
                                        return Stack(children: [
                                          Container(
                                              padding: EdgeInsets.symmetric(
                                                  horizontal:
                                                      ScreenUtil().setSp(30),
                                                  vertical:
                                                      ScreenUtil().setSp(30)),
                                              width: MediaQuery.of(context)
                                                  .size
                                                  .width,
                                              margin: EdgeInsets.symmetric(
                                                  horizontal:
                                                      ScreenUtil().setSp(10)),
                                              decoration: BoxDecoration(
                                                  color: [
                                                    Colors.black,
                                                    Colors.blue,
                                                    Colors.cyan,
                                                    Colors.green,
                                                    Colors.grey
                                                  ][item % 5],
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          ScreenUtil()
                                                              .setSp(20))),
                                              child: Column(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceEvenly,
                                                children: <Widget>[
                                                  Row(
                                                    children: <Widget>[
                                                      Text(
                                                        "收货人:",
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(30)),
                                                      ),
                                                      SizedBox(
                                                        width: ScreenUtil()
                                                            .setSp(10),
                                                      ),
                                                      Text(
                                                          index
                                                              .infoModel
                                                              .data
                                                              .address[item]
                                                              .name,
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.white,
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          30)))
                                                    ],
                                                  ),
                                                  Row(
                                                    children: <Widget>[
                                                      Text(
                                                        "手机号码:",
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(30)),
                                                      ),
                                                      SizedBox(
                                                        width: ScreenUtil()
                                                            .setSp(10),
                                                      ),
                                                      Text(
                                                          index
                                                              .infoModel
                                                              .data
                                                              .address[item]
                                                              .tel,
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.white,
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          30)))
                                                    ],
                                                  ),
                                                  Row(
                                                    children: <Widget>[
                                                      Container(
                                                          margin: EdgeInsets.only(
                                                              right:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          10)),
                                                          child: Row(
                                                            children: <Widget>[
                                                              Text(
                                                                "省份:",
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white,
                                                                    fontSize: ScreenUtil()
                                                                        .setSp(
                                                                            30)),
                                                              ),
                                                              SizedBox(
                                                                width:
                                                                    ScreenUtil()
                                                                        .setSp(
                                                                            10),
                                                              ),
                                                              Text(
                                                                  province_list[index
                                                                      .infoModel
                                                                      .data
                                                                      .address[
                                                                          item]
                                                                      .province],
                                                                  style: TextStyle(
                                                                      color: Colors
                                                                          .white,
                                                                      fontSize:
                                                                          ScreenUtil()
                                                                              .setSp(30)))
                                                            ],
                                                          )),
                                                      Container(
                                                          margin: EdgeInsets.only(
                                                              right:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          10)),
                                                          child: Row(
                                                            children: <Widget>[
                                                              Text(
                                                                "城市:",
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white,
                                                                    fontSize: ScreenUtil()
                                                                        .setSp(
                                                                            30)),
                                                              ),
                                                              SizedBox(
                                                                width:
                                                                    ScreenUtil()
                                                                        .setSp(
                                                                            10),
                                                              ),
                                                              Text(
                                                                  city_list[index
                                                                      .infoModel
                                                                      .data
                                                                      .address[
                                                                          item]
                                                                      .city],
                                                                  style: TextStyle(
                                                                      color: Colors
                                                                          .white,
                                                                      fontSize:
                                                                          ScreenUtil()
                                                                              .setSp(30)))
                                                            ],
                                                          )),
                                                      Container(
                                                          margin: EdgeInsets.only(
                                                              right:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          10)),
                                                          child: Row(
                                                            children: <Widget>[
                                                              Text(
                                                                "区县:",
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white,
                                                                    fontSize: ScreenUtil()
                                                                        .setSp(
                                                                            30)),
                                                              ),
                                                              SizedBox(
                                                                width:
                                                                    ScreenUtil()
                                                                        .setSp(
                                                                            10),
                                                              ),
                                                              Text(
                                                                  county_list[index
                                                                      .infoModel
                                                                      .data
                                                                      .address[
                                                                          item]
                                                                      .county],
                                                                  style: TextStyle(
                                                                      color: Colors
                                                                          .white,
                                                                      fontSize:
                                                                          ScreenUtil()
                                                                              .setSp(30)))
                                                            ],
                                                          )),
                                                    ],
                                                  ),
                                                  Row(
                                                    children: <Widget>[
                                                      Text("详细地址:",
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.white,
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          30))),
                                                      SizedBox(
                                                        width: ScreenUtil()
                                                            .setSp(10),
                                                      ),
                                                      Text(
                                                          index
                                                              .infoModel
                                                              .data
                                                              .address[item]
                                                              .addressDetail,
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.white,
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          30))),
                                                    ],
                                                  )
                                                ],
                                              )),
                                          Positioned(
                                            top: ScreenUtil().setSp(10),
                                            right: ScreenUtil().setSp(10),
                                            child: FlatButton(
                                                onPressed: () {},
                                                child: Row(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.center,
                                                  children: <Widget>[
                                                    Text("默认地址",
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(
                                                                        30))),
                                                    Container(
                                                        width: ScreenUtil()
                                                            .setSp(50),
                                                        height: ScreenUtil()
                                                            .setSp(50),
                                                        child: Radio<bool>(
                                                            value: true,
                                                            groupValue: index
                                                                .infoModel
                                                                .data
                                                                .address[item]
                                                                .isDefault,
                                                            onChanged: (value) {
                                                              index.replaceCode(
                                                                  item);
                                                            },
                                                            activeColor:
                                                                Colors.white)),
                                                  ],
                                                )),
                                          ),
                                          Positioned(
                                            bottom: ScreenUtil().setSp(10),
                                            right: ScreenUtil().setSp(10),
                                            child: FlatButton(
                                                onPressed: () {
                                                  index.delAddress(index
                                                      .infoModel
                                                      .data
                                                      .address[item]
                                                      .id);
                                                },
                                                child: Row(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.center,
                                                  children: <Widget>[
                                                    Text("删除",
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(
                                                                        30))),
                                                    Container(
                                                        width: ScreenUtil()
                                                            .setSp(40),
                                                        height: ScreenUtil()
                                                            .setSp(40),
                                                        child: Icon(
                                                          Icons.delete,
                                                          color: Colors.white,
                                                          size: ScreenUtil()
                                                              .setSp(40),
                                                        )),
                                                  ],
                                                )),
                                          ),
                                          Positioned(
                                            bottom: ScreenUtil().setSp(10),
                                            right: ScreenUtil().setSp(120),
                                            child: FlatButton(
                                                onPressed: () {
                                                  showDialog(
                                                      context: context,
                                                      builder: (_) {
                                                        return AddressEditPage(
                                                          address: index
                                                              .infoModel
                                                              .data
                                                              .address[item],
                                                        );
                                                      });
                                                },
                                                child: Row(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.center,
                                                  children: <Widget>[
                                                    Text("编辑",
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(
                                                                        30))),
                                                    Container(
                                                        width: ScreenUtil()
                                                            .setSp(40),
                                                        height: ScreenUtil()
                                                            .setSp(40),
                                                        child: Icon(
                                                          Icons.edit,
                                                          color: Colors.white,
                                                          size: ScreenUtil()
                                                              .setSp(40),
                                                        )),
                                                  ],
                                                )),
                                          )
                                        ]);
                                      },
                                    );
                                  }).toList())
                              : Container(
                                  alignment: Alignment.center,
                                  child: Text("请先添加地址"),
                                ),
                        ),
                        Positioned(
                          right: ScreenUtil().setSp(0),
                          top: ScreenUtil().setSp(0),
                          child: InkWell(
                            onTap: () {
                              showDialog(
                                  context: context,
                                  builder: (_) {
                                    return Provide<InfoProvider>(
                                        builder: (context, child, code) {
                                      return Scaffold(
                                          body: GestureDetector(
                                        child: Stack(children: [
                                          Positioned(
                                              right: ScreenUtil().setWidth(10),
                                              top: ScreenUtil().setWidth(10),
                                              child: IconButton(
                                                icon: Icon(Icons.close),
                                                onPressed: () {
                                                  Navigator.of(context).pop();
                                                },
                                              )),
                                          Container(
                                            padding: EdgeInsets.symmetric(
                                                horizontal:
                                                    ScreenUtil().setWidth(30),
                                                vertical: ScreenUtil()
                                                    .setHeight(120)),
                                            height:
                                                ScreenUtil().setHeight(1800),
                                            child: Column(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.spaceEvenly,
                                              children: <Widget>[
                                                TextField(
                                                  textInputAction:
                                                      TextInputAction.done,
                                                  onChanged: (value) {
                                                    code.setSomeThing(
                                                        name: value);
                                                  },
                                                  //  keyboardType:TextInputType.,
                                                  // obscureText: true,
                                                  style: TextStyle(
                                                      color: Colors.black),
                                                  decoration: InputDecoration(
                                                    border: OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    enabledBorder:
                                                        OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    labelText: '收货人',
                                                    labelStyle: TextStyle(
                                                        color: Colors.black),
                                                    hintText: '请输入收货人',
                                                    focusColor: Colors.black,
                                                    focusedBorder:
                                                        InputBorder.none,
                                                  ),
                                                ),
                                                TextField(
                                                  textInputAction:
                                                      TextInputAction.done,
                                                  onChanged: (value) {
                                                    code.setSomeThing(
                                                        tel: value);
                                                  },
                                                  keyboardType:
                                                      TextInputType.number,
                                                  inputFormatters: [
                                                    WhitelistingTextInputFormatter
                                                        .digitsOnly
                                                  ], //只允许输入数字
                                                  // obscureText: true,
                                                  style: TextStyle(
                                                      color: Colors.black),
                                                  decoration: InputDecoration(
                                                    border: OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    enabledBorder:
                                                        OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    labelText: '收货号码',
                                                    labelStyle: TextStyle(
                                                        color: Colors.black),
                                                    hintText: '请输入收货号码',
                                                    focusColor: Colors.black,
                                                    focusedBorder:
                                                        InputBorder.none,
                                                  ),
                                                ),
                                                InkWell(
                                                    onTap: () {
                                                      show();
                                                    },
                                                    child: Container(
                                                        padding: EdgeInsets
                                                            .symmetric(
                                                                vertical:
                                                                    ScreenUtil()
                                                                        .setHeight(
                                                                            10)),
                                                        decoration:
                                                            BoxDecoration(
                                                          border: Border.all(
                                                              width:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          2)),
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(
                                                                      15.0),
                                                        ),
                                                        child: Row(
                                                          mainAxisAlignment:
                                                              MainAxisAlignment
                                                                  .spaceEvenly,
                                                          children: <Widget>[
                                                            Container(
                                                              alignment:
                                                                  Alignment
                                                                      .center,
                                                              padding: EdgeInsets.symmetric(
                                                                  horizontal:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              40),
                                                                  vertical:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              20)),
                                                              color: Colors
                                                                  .cyan[400],
                                                              width:
                                                                  ScreenUtil()
                                                                      .setWidth(
                                                                          200),
                                                              child: Text(
                                                                province_list[
                                                                    code.code1],
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white),
                                                              ),
                                                            ),
                                                            Container(
                                                              alignment:
                                                                  Alignment
                                                                      .center,
                                                              padding: EdgeInsets.symmetric(
                                                                  horizontal:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              40),
                                                                  vertical:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              20)),
                                                              color: Colors
                                                                  .cyan[400],
                                                              width:
                                                                  ScreenUtil()
                                                                      .setWidth(
                                                                          200),
                                                              child: Text(
                                                                city_list[
                                                                    code.code2],
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white),
                                                              ),
                                                            ),
                                                            Container(
                                                              alignment:
                                                                  Alignment
                                                                      .center,
                                                              padding: EdgeInsets.symmetric(
                                                                  horizontal:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              40),
                                                                  vertical:
                                                                      ScreenUtil()
                                                                          .setWidth(
                                                                              20)),
                                                              color: Colors
                                                                  .cyan[400],
                                                              width:
                                                                  ScreenUtil()
                                                                      .setWidth(
                                                                          200),
                                                              child: Text(
                                                                county_list[
                                                                    code.code3],
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white),
                                                              ),
                                                            ),
                                                          ],
                                                        ))),
                                                TextField(
                                                  textInputAction:
                                                      TextInputAction.done,
                                                  onChanged: (value) {
                                                    code.setSomeThing(
                                                        addressDetail: value);
                                                  },
                                                  style: TextStyle(
                                                      color: Colors.black),
                                                  decoration: InputDecoration(
                                                    border: OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    enabledBorder:
                                                        OutlineInputBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              15.0),
                                                      //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
                                                    ),
                                                    labelText: '详细地址',
                                                    labelStyle: TextStyle(
                                                        color: Colors.black),
                                                    hintText: '详细地址',
                                                    focusColor: Colors.black,
                                                    focusedBorder:
                                                        InputBorder.none,
                                                  ),
                                                ),
                                                Row(children: [
                                                  Text("设置为默认地址"),
                                                  Checkbox(
                                                    value: code.address
                                                            .isDefault ??
                                                        false, //是否选中 true选中  false不选中
                                                    onChanged: (value) {
                                                      code.setSomeThing(
                                                          isDefault: value);
                                                    },
                                                    tristate:
                                                        true, //默认false，但当为true时表示增加中间状态值，onchange的value：true 选中，null中间状态，false 不选中。
                                                    activeColor: Colors.cyan[
                                                        400], //框的背景色，点击的效果色
                                                    checkColor: Colors
                                                        .white, // 中间的对勾颜色，中间状态的横杠颜色
                                                  )
                                                ]),
                                              ],
                                            ),
                                          ),
                                          Positioned(
                                              right: ScreenUtil().setWidth(40),
                                              bottom:
                                                  ScreenUtil().setHeight(40),
                                              child: InkWell(
                                                  onTap: () {
                                                    code.save();
                                                    Navigator.pop(context);
                                                  },
                                                  child: Container(
                                                      padding:
                                                          EdgeInsets.symmetric(
                                                              horizontal:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          40),
                                                              vertical:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          20)),
                                                      color: Colors.cyan[400],
                                                      margin: EdgeInsets.only(
                                                          left: ScreenUtil()
                                                              .setSp(60)),
                                                      child: Text(
                                                        "确认",
                                                        style: TextStyle(
                                                            color:
                                                                Colors.white),
                                                      ))))
                                        ]),
                                        onTap: () {
                                          return false;
                                        },
                                      ));
                                    });
                                  });
                            },
                            child: Row(
                              children: <Widget>[
                                Text("添加地址",
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30))),
                                Icon(Icons.add, size: ScreenUtil().setSp(40)),
                              ],
                            ),
                          ),
                        )
                      ]),
                      InkWell(
                          onTap: () {
                            logout();
                          },
                          child: Container(
                            margin: EdgeInsets.only(
                                top: ScreenUtil().setHeight(10)),
                            alignment: Alignment.center,
                            color: Colors.cyan[400],
                            height: ScreenUtil().setHeight(100),
                            width: ScreenUtil().setWidth(400),
                            child: Text("退出账号",
                                style: TextStyle(color: Colors.white)),
                          ))
                    ],
                  )),
            );
    });
  }

  logout() async {
    Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
    await _prefs.then((ins) async {
      ins.clear();
      Provide.value<AuthProvider>(context).setToken(null);
      Navigator.of(context).pushAndRemoveUntil(
          new MaterialPageRoute(builder: (context) => HomePage()),
          (route) => route == null);
    });
  }
}
